package cn.xo68.demo.client.controller;

import cn.xo68.boot.auth.core.domain.Oauth2Principal;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class IndexController {

    @GetMapping({"/"})
    public String main(){
        return "success";
    }

    @GetMapping({"/index"})
    public Oauth2Principal index(){
        Subject subject = SecurityUtils.getSubject();

        return (Oauth2Principal) subject.getPrincipal();
    }

    @RequiresPermissions("index:main")
    @GetMapping({"/index2"})
    public String index2(){
        return "success";
    }
}
